<template >
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <!-- 点击首页会跳转到home -->
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片试图区 -->
    <el-card class="box-card">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getOrdersList">
            <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table :data="ordersList" stripe border>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template v-slot="scope">
            <el-tag type="primary" size="mini" v-if="scope.row.pay_status==='1'">已付款</el-tag>
            <el-tag type="danger" size="mini" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template v-slot="scope">{{scope.row.create_time|dateFomat}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button class="el-icon-edit" type="primary" size="mini" @click="editOrdersShow">编辑</el-button>

            <el-button
              class="el-icon-location-information"
              type="danger"
              size="mini"
              @click="progressShow"
            >物流信息</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15,20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 修改地址窗口 -->
    <el-dialog title="修改地址" :visible.sync="dialogVisibleEdit" width="50%" @close="resetEdit">
      <el-form :model="editForm" :rules="editRules" ref="editFormRef">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="editForm.address1"
            :options="citydata"
            :props="{ expandTrigger: 'hover' }"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="editForm.address2"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleEdit = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisibleEdit = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流信息窗口 -->
    <el-dialog title="查看物流进度" :visible.sync="dialogVisibleProgress" width="50%">
      <!-- 时间线 -->
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in progressInfo"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleProgress = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisibleProgress= false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
//导入省份信息
import citydata from "./citydata.js";

export default {
  data() {
    return {
      //订单接收数据
      ordersList: [],
      //查询
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 5
      },
      //数据总数
      total: 0,
      //省份信息
      citydata,
      //控制编辑窗口显示
      dialogVisibleEdit: false,
      //控制物流信息窗口显示

      dialogVisibleProgress: false,
      //物流信息
      progressInfo: [],

      //存放地址表单
      editForm: {
        address1: [],
        address2: ""
      },

      editRules: {
        address1: [
          { required: true, message: "请输入省市区/县", trigger: "blur" }
        ],
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getOrdersList();
  },
  methods: {
    async getOrdersList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo
      });
      if (res.meta.status !== 200) {
        return this.$message.error("获取失败");
      } else {
        console.log(res);
        this.total = res.data.total;
        this.ordersList = res.data.goods;
      }
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrdersList();
    },
    handleCurrentChange(nesNum) {
      this.queryInfo.pagenum = nesNum;
      this.getOrdersList();
    },
    //显示编辑窗口
    editOrdersShow() {
      this.dialogVisibleEdit = true;
    },
    //重置表单
    resetEdit() {
      this.$refs.editFormRef.resetFields("editForm");
    },
    // //编辑地址信息
    // editOrders() {
    //   this.$refs.editFormRef.validate(async valid => {
    //     if (!valid) {
    //       return;
    //     } else {
    //       const { data: res } = await this.$http.put(
    //         "orders/" + user_id,
    //         this.editForm.user_id
    //       );
    //       if (res.meta.status !== 200) {
    //         return this.$message.error("获取失败");
    //       } else {
    //         this.getOrdersList();
    //         this.dialogVisibleEdit = false;
    //         this.$message.success("编辑成功");
    //       }
    //     }
    //   });
    // }
    async progressShow() {
      const { data: res } = await this.$http.get("/kuaidi/1106975712662");
      if (res.meta.status !== 200) {
        return this.$message.error("获取失败");
      } else {
        this.progressInfo = res.data;
        this.dialogVisibleProgress = true;
      }
    }
  }
};
</script>
import 
<style lang="less" scoped>
.el-cascader {
  width: 100%;
}
</style>